/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
 */
/*
 * xmlTest.java
 *
 * Created on October 3, 2002, 9:52 AM
 */

package tests.jd;

import com.webdeninteractive.xbotts.Mapping.schema.*;
import com.webdeninteractive.xbotts.Mapping.compiler.*;
import com.webdeninteractive.xbotts.Utility.*;
import org.w3c.dom.*;
import java.util.*;

/**
 *
 * @author  jdepons
 */
public class xmlTest {
    
            
    /** Creates a new instance of xmlTest */
    public xmlTest() {
    }
    
    /**
     * 
     */
    Linkable buildTree( Document schema )throws Exception{
        Linkable root = new Record("/");
        root.setStructure(Linkable.ROOT);
        SchemaContext sc = new SchemaContext( );
        Element schemaElement = schema.getDocumentElement( );
        sc.setLocationPath(locationPath);
        sc.initialize(schemaElement);
        sc.handleNode(root, (Element)schemaElement.getElementsByTagName("xs:element").item(0));
        return root;
    }
    
    /**
     * Traverses a tree, printing out the name of each node.
     */
    public void traverse(String indent, Linkable node){
        System.out.print(indent + node.getName());
        
        if (node instanceof Record) {
            Record record = (Record)node;
            System.out.print(" max=" + record.getMaxOccurence() + " min=" + record.getMinOccurence() + "\n");            
        }else {
            System.out.print(" attomic\n");
        }
        
        if(node instanceof Record){
            indent = indent+"|---";
            Enumeration enum = ((Record)node).children( );
            while(enum.hasMoreElements()){
                traverse(indent, (Linkable)enum.nextElement( ));
            }
        }
        
    
    }
    String locationPath;
    
    public static void main(String[] args)throws Exception{
        if(args.length<1){
          //  System.out.println("Usage: UsageExample [schemaLocation]");
          //  return;
        }
        xmlTest usage = new xmlTest( );
        usage.locationPath  = "c:\\OAGIS8.0\\OAGIS\\BODs\\AddPurchaseOrder.xsd";
        Document schema = XMLTools.createDocumentNS(usage.locationPath,false);
        Linkable tree = usage.buildTree(schema);
        usage.traverse("",tree);
    }
    
}
